/*
 *  objcExt.h
 *  CocoaMoney
 *
 *  Created by Daniel Braun on 30/11/06.
 *  Copyright 2006 Daniel Braun http://braun.daniel.free.fr. All rights reserved.
 *
 */

#ifndef OBJC_EXT
#define OBJC_EXT

#include "objc/objc-runtime.h"

#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
#define _LEOPARD 1
#else
#define _LEOPARD 0
#endif


static inline SEL selFromString(NSString *s)
{
	if (!s) return (SEL)0;
#if !_LEOPARD
	SEL sel=sel_registerName([s UTF8String]);
	if (!sel_isMapped(sel)) sel=(SEL)0;
#else
	SEL sel=sel_getUid([s UTF8String]);
#endif
	return sel;
}

#define isSubclassOf(a,b) issubclass(a,b)

#if !_LEOPARD

static inline BOOL issubclass(Class x, Class p)
{
	struct objc_class *cx=(struct objc_class *)x;
	for (;cx;cx=cx->super_class) {
		if (cx==(struct objc_class *)p) return YES;
	}
	return NO;
}
#else
static inline BOOL issubclass(Class x, Class p)
{
	Class cx=x;
	for (;cx;cx=class_getSuperclass(cx)) {
		if (cx==p) return YES;
	}
	return NO;
}

#endif

Class * getAllClasses(int *numClasses);
NSArray *getAllSubclassesOf(Class p);

#endif
